package com.wq.sort;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Random;

/**
 * @Author: wangqiang20995
 * @Date:2019/2/28
 * @Description:
 * @Resource:
 */
public abstract class BaseSort {

    protected int[] array;

    public BaseSort(int size){
        this.array = new int[size];
        Random random = new Random();

        for(int i = 0;i<size;i++){
            this.array[i] = random.nextInt(100000);
        }
    }

    public void printArray(boolean print){
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sort.txt")));

            for(int i = 0;i<array.length;i++){
                writer.write(String.valueOf(array[i]));
                writer.write('\t');
                if (print) {
                    System.out.printf("%d\t", array[i]);
                }
            }
            writer.write('\n');
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (print) {
            System.out.println();
        }
    }

}
